﻿using System;
using System.Text.RegularExpressions;
using Assets.Scripts.GtsScripts;
using UnityEngine;

// Token: 0x020001C0 RID: 448
public class Destructor : MonoBehaviour
{
	// Token: 0x0600091E RID: 2334 RVA: 0x000552BC File Offset: 0x000534BC
	private void OnCollisionEnter(Collision collision)
	{
		if (collision.gameObject.layer != Layers.buildingLayer)
		{
			return;
		}
		if (this.Secondary)
		{
			return;
		}
		IDestructible componentInParent = collision.gameObject.GetComponentInParent<IDestructible>();
		if (componentInParent == null)
		{
			return;
		}
		if (base.gameObject.layer == Layers.playerLayer && !GlobalPreferences.MicroPlayerBuildingDestruction.value && base.gameObject.GetComponent<EntityBase>().isMicro)
		{
			return;
		}
		if (base.gameObject.layer == Layers.gtsBodyLayer || base.gameObject.layer == Layers.destroyerLayer)
		{
			Giantess componentInParent2 = base.GetComponentInParent<Giantess>();
			if (!GlobalPreferences.GtsPlayerBuildingDestruction.value && componentInParent2.isPlayer)
			{
				return;
			}
			if (!GlobalPreferences.GtsBuildingDestruction.value && !componentInParent2.isPlayer)
			{
				return;
			}
		}
		float heightMesh = base.gameObject.GetComponentInParent<EntityBase>().HeightMesh;
		float y = collision.gameObject.GetComponent<Collider>().bounds.extents.y;
		if (base.gameObject.layer != Layers.destroyerLayer && heightMesh < y)
		{
			return;
		}
		if (base.gameObject.GetComponentInParent<EntityBase>().isMicro)
		{
			componentInParent.Destroy(collision.contacts[0].point, float.MaxValue, true, true, true);
			return;
		}
		if (collision.transform.parent != null && Regex.IsMatch(collision.transform.parent.gameObject.name, "U_Char\\d+"))
		{
			this.Secondary = true;
			componentInParent.Destroy(collision.contacts[0].point, float.MaxValue, true, true, false);
		}
		else
		{
			componentInParent.Destroy(collision.contacts[0].point, y, false, false, false);
		}
	}

	// Token: 0x04000EE5 RID: 3813
	public float baseSize = 1f;

	// Token: 0x04000EE6 RID: 3814
	public bool Secondary;
}
